package com.ruoyi.controller;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.domain.BusActivity;
import com.ruoyi.service.IBusActivityService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 走访活动Controller
 *
 * @author ruoyi
 * @date 2024-01-30
 */
@RestController
@RequestMapping("/bus/activity")
public class BusActivityController extends BaseController
{
    @Autowired
    private IBusActivityService busActivityService;

    /**
     * 查询走访活动列表
     */
    @PreAuthorize("@ss.hasPermi('system:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusActivity busActivity)
    {
        startPage();
        List<BusActivity> list = busActivityService.selectBusActivityList(busActivity);
        return getDataTable(list);
    }

    /**
     * 导出走访活动列表
     */
    @PreAuthorize("@ss.hasPermi('system:activity:export')")
    @Log(title = "走访活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusActivity busActivity)
    {
        List<BusActivity> list = busActivityService.selectBusActivityList(busActivity);
        ExcelUtil<BusActivity> util = new ExcelUtil<BusActivity>(BusActivity.class);
        util.exportExcel(response, list, "走访活动数据");
    }

    /**
     * 获取走访活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:activity:query')")
    @GetMapping(value = "/{busActivityId}")
    public AjaxResult getInfo(@PathVariable("busActivityId") Long busActivityId)
    {
        return success(busActivityService.selectBusActivityByBusActivityId(busActivityId));
    }

    /**
     * 新增走访活动
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('system:activity:add')")
    @Log(title = "走访活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusActivity busActivity)
    {
        return toAjax(busActivityService.insertBusActivity(busActivity));
    }

    /**
     * 修改走访活动
     */
    @PreAuthorize("@ss.hasPermi('system:activity:edit')")
    @Log(title = "走访活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusActivity busActivity)
    {
        return toAjax(busActivityService.updateBusActivity(busActivity));
    }

    /**
     * 删除走访活动
     */
    @PreAuthorize("@ss.hasPermi('system:activity:remove')")
    @Log(title = "走访活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{busActivityIds}")
    public AjaxResult remove(@PathVariable Long[] busActivityIds)
    {
        return toAjax(busActivityService.deleteBusActivityByBusActivityIds(busActivityIds));
    }
}
